/*
 * @Description: form builder
 * @Author: Rfan
 * @Date: 2021-10-09 17:47:40
 * @LastEditTime: 2022-09-08 14:29:28
 */

import { useEffect, useState } from 'react';
import { appActions } from '@/store/mobx';
import { LeggoConfigs } from '@/components/form-builder';
import { fetchMetadata } from '@/api/metadata';
import { QUERY_METADATA_ALL } from '@/view/system/Metadata/constants';
import '../../../components/form-builder/styles/configs.less';

const Builder = () => {
  const [list, setList] = useState([]);

  useEffect(() => {
    const fieldQuery = {
      metadataFieldType: QUERY_METADATA_ALL,
      coordinate: {
        atType: 1,
        atCode: 100,
        level: 2
      }
    };
    fetchMetadata(fieldQuery).then((res) => {
      setList(res.data);
    });
  }, []);

  const postSchemaModelData = (schemaModel: any) => {
    console.log('发送schema～～～～～～', schemaModel);
    appActions.setFormSchema(JSON.parse(JSON.stringify(schemaModel)));
  };

  return (
    <>
      <LeggoConfigs onGetSchemaModel={postSchemaModelData} fieldList={list} />
    </>
  );
};

export default Builder;
